home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gwuada_8.zip / CWKTASK.C < prev    next >
C/C++ Source or Header  |  1993-12-29  |  20KB  |  733 lines

  1.  
  2.  
  3. /*
  4.     GWMON Parallel Ada Monitor for 386/486 PCs   
  5.     Copyright (C) 1993, Charles W. Kann  & Michael Bliss Feldman
  6.                         ckann@seas.gwu.edu mfeldman@seas.gwu.edu
  7.  
  8.     This program is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License as published by
  10.     the Free Software Foundation; either version 2 of the License.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21. */
  22.  
  23. #include "ed.h"
  24. #include "keydef.h"
  25. /*
  26.     I need the variable "exception_trace" from ivars.h.  I don't want
  27.     to use the whole .h, so I am including this one variable here.
  28. */
  29. extern int exception_trace;
  30.  
  31. static int current_task;
  32. static int save_block_number = -1;
  33. static long Run_Current_Time; /* Run time (lines) since last report */
  34. extern rr_flag;
  35. void CWK_SET_TASK();
  36. void CWK_SET_TASK_LINE();
  37. void CWK_GET_KEY();
  38. static void scroll_tasks();
  39.  
  40. void busy_wait(wait_cnt)
  41. int wait_cnt;
  42. {
  43.     int i, cycles;
  44.     cycles = delay_scaling_factor * delay_array[wait_cnt];
  45.     for ( i = 0; i < cycles; ++i );
  46. }
  47.  
  48. void CWK_CREATE_TASK(task_no, task_name, task_file)
  49. int task_no;
  50. char *task_name;
  51. char *task_file;
  52. {
  53.     char msg[100];
  54.     int ch;
  55.  
  56.     if ( task_no > MAX_TSKS ) {
  57.     printf("Can't work with more than %d tasks...", MAX_TSKS-1);
  58.     }
  59.     /*
  60.     Find the task particulars in the task file (For now, hard code them)
  61.     */
  62.     CWK_TASKS[task_no].TN = malloc( strlen(task_name)+1 );
  63.     strcpy( CWK_TASKS[task_no].TN, task_name );
  64.     CWK_TASKS[task_no].FL = 1;
  65.     CWK_TASKS[task_no].LL = 10000;
  66.     CWK_TASKS[task_no].FLOS = 0;
  67.     CWK_TASKS[task_no].CL = 0;
  68.     CWK_TASKS[task_no].MON = CWK_CREATE_MON_WIN(CWK_TASKS[task_no].TN, 
  69.         (monitor_type == 1) ? 1 : 0 );
  70.         CWK_TASKS[task_no].FD = CWK_LOAD_FILE(task_file);
  71. }
  72.  
  73. /*************************************************************************/
  74. /*                                     */
  75. /*    CWK_Switch_Block is used to make sure the correct program block  */
  76. /*    (ie procedure, package, task, etc) is being used.  When a program*/
  77. /*    block becomes current, we want to make sure that we then move to */
  78. /*    use that program block.  Program blocks are entered and exited   */
  79. /*    inta.c.  We call this routine from there.             */
  80. /*                                     */
  81. /*    parameters:                             */
  82. /*        block_number : the block number of this block           */
  83. /*        block_name   : the title of the block (ie proc name)     */
  84. /*        block_file   : file which contains this block            */
  85. /*         enter_or_exit: Are we entering or exiting this block     */
  86. /*                   This is only used in procedure monitoring */
  87. /*                   If this is 1 - exiting, 0 - entering     */
  88. /*                                     */
  89. /*************************************************************************/
  90.  
  91. CWK_Switch_Block( block_number, block_name, block_package, block_file, 
  92.           enter_or_exit )
  93. int block_number, enter_or_exit;
  94. char *block_name, *block_package, *block_file;
  95. {
  96.     FILE_REC_PTR Save_FD;
  97.     char package_routine[68];
  98.  
  99.     /*
  100.         In the case of task monitoring, if the new procedure is in
  101.         a different source file from the one currently being used,
  102.         move to that source file.
  103.     */ 
  104.     
  105.     if ( task_monitor )
  106.     {
  107.             Save_FD = CWK_TASKS[current_task].FD;
  108.             CWK_TASKS[current_task].FD = CWK_LOAD_FILE(block_file);
  109.             if ( Save_FD != CWK_TASKS[current_task].FD )
  110.                     CWK_TASKS[current_task].FLOS = 0;
  111.     }
  112.  
  113.     /*
  114.         Procedure monitoring
  115.     */
  116.     else
  117.     {
  118.         /*
  119.             The save_block_number remembers the block between
  120.             calls.  The first time through, however, it must be set
  121.         */
  122.         if ( save_block_number == -1 )
  123.             save_block_number = block_number;
  124.  
  125.         /*
  126.             If this block hasn't been created, and we have a valid
  127.             block, create it.  If the block is part of a package,
  128.             prepend the package name.
  129.         */
  130.  
  131.         if ( strcmp( block_package, "main" ) != 0 )
  132.         {
  133.                 strcpy( package_routine, block_package );
  134.                 strcat( package_routine, "." );
  135.                 strcat( package_routine, block_name );
  136.         }
  137.         else
  138.                 strcpy( package_routine, block_name );
  139.  
  140.         if  ( CWK_BLKS[block_number].MON == NULL ) 
  141.             CWK_CREATE_BLOCK(block_number, package_routine, 
  142.                      block_file );
  143.  
  144.         /*
  145.             Only worry about monitor windows if the monitor is
  146.             running.
  147.         */
  148.  
  149.         if ( monitor_type != 1 )
  150.             return;
  151.         
  152.         if ( monitor_window_type == 3 )
  153.         {
  154.             save_block_number = block_number;
  155.             CWK_DRAW_PROC_WIN( CWK_BLKS[block_number].MON, 
  156.                 enter_or_exit );
  157.  
  158.                 CWK_BLKS[save_block_number].FLOS = 0;
  159. #if 0
  160.             CWK_SET_TASK_LINE( CWK_BLKS[block_number].CL, 0 );
  161. #endif
  162.  
  163.             /*
  164.                 If the mode is to be in task step mode,
  165.                 then wait for a key to be pressed to
  166.                 move to the next step, otherwise, wait
  167.                 a second to keep the screen from flashing.
  168.             */
  169.  
  170.             if ( task_step )
  171.                      CWK_GET_KEY( 1 );
  172.             else
  173.                 busy_wait( MAX_DELAY-1 );
  174.         }
  175.         else
  176.             save_block_number = block_number;
  177.             
  178.     }
  179. }
  180.  
  181. CWK_LEAVE_BLOCK( block_number )
  182. int block_number;
  183. {
  184.     if ( monitor_type != 1 )
  185.         return;
  186.     if ( ! task_monitor )
  187.         CWK_REMOVE_BLOCK( CWK_BLKS[block_number].MON);
  188. }
  189.  
  190. /*************************************************************************/
  191. /*************************************************************************/
  192.     
  193. void CWK_DISTROY_TASK(task_no)
  194. int task_no;
  195. {
  196.     CWK_TASKS[task_no].TN = "";
  197.     CWK_TASKS[task_no].FL = 0;
  198.     CWK_TASKS[task_no].LL = 0;
  199.     CWK_DEL_MON_WIN(CWK_TASKS[task_no].MON);
  200. }
  201.     
  202. void CWK_CHANGE_TASK_STAT(task_no, stat, task_name, task_file )
  203. int task_no;
  204. char stat;
  205. char *task_name, *task_file;
  206. {
  207.     int FLOS;
  208.     FLOS = CWK_TASKS[task_no].FLOS;
  209.  
  210.     if ( ! task_monitor )
  211.         return;
  212.  
  213.     CWK_TASKS[task_no].ST = stat;
  214.  
  215.     switch( stat ) {
  216.         case 'C' :      /* Create a new task */
  217.         CWK_CREATE_TASK( task_no, task_name, task_file );
  218.         CWK_TASKS[task_no].ST = '*';
  219.         break;
  220.         case 'A' :     /* Activate a task */
  221.         CWK_SET_TASK( task_no );
  222.         CWK_TASKS[task_no].ST = '*';
  223.         if ( ( task_step ) && ( CWK_TASKS[task_no].MON->WON == 1 ) )
  224.                  CWK_GET_KEY( 1 );
  225.         break;
  226.         case 'S' :    /* Change to a new task */
  227.         CWK_SET_TASK( task_no );
  228.         CWK_TASKS[task_no].ST = '*';
  229.         break;
  230.         case 'D' :    /* Delaying task       */
  231.         if ( monitor_type == 1 )
  232.         {
  233.             CWK_CUR_LINE( CWK_TASKS[task_no].MON, 
  234.                 CWK_TASKS[task_no].CL- FLOS, " D " );
  235.             if ( ( task_step ) && 
  236.                  ( CWK_TASKS[task_no].MON->WON == 1 ) )
  237.                      CWK_GET_KEY( 1 );
  238.         }
  239.         break;
  240.         case 'R' :    /* Waiting Rendezvous  */
  241.         if ( monitor_type == 1 )
  242.         {
  243.             CWK_CUR_LINE( CWK_TASKS[task_no].MON,
  244.                 CWK_TASKS[task_no].CL- FLOS, " R " );
  245.             if ( ( task_step ) && 
  246.                  ( CWK_TASKS[task_no].MON->WON == 1 ) )
  247.                      CWK_GET_KEY( 1 );
  248.         }
  249.         break;
  250.         case 'M' :    /* Rendezvous Met  */
  251.         if ( monitor_type == 1 )
  252.         {
  253.             CWK_CUR_LINE( CWK_TASKS[task_no].MON,
  254.                 CWK_TASKS[task_no].CL- FLOS, " M " );
  255.             if ( ( task_step ) && 
  256.                  ( CWK_TASKS[task_no].MON->WON == 1 ) )
  257.                      CWK_GET_KEY( 1 );
  258.         }
  259.         break;
  260.         case 'E' :    /* Rendezvous Met  */
  261.         CWK_DISTROY_TASK( task_no );
  262.         break;
  263.         }
  264. }
  265.  
  266. void CWK_SET_TASK_LINE( line_no, getkey_or_not )
  267. int line_no, getkey_or_not;
  268. {
  269.     int i;
  270.     int FLOS;
  271.     static text_string[50], format_string[50];
  272.  
  273.     TASK_REC *temp_task;
  274.     int task_no;
  275.  
  276.     if ( task_monitor )
  277.     {
  278.         task_no = current_task;
  279.         temp_task = CWK_TASKS;
  280.     }
  281.     else
  282.     {
  283.         task_no = save_block_number;
  284.         temp_task = CWK_BLKS;
  285.     }
  286.  
  287.         if ( temp_task[task_no].FD->lines_in_file < line_no )
  288.     {
  289.         return;
  290.     }
  291.  
  292.     if ( ( temp_task[task_no].MON->WON != 1 )  ||
  293.          ( monitor_type != 1 ) )
  294.     {
  295.         return;
  296.     }
  297.  
  298.     FLOS = temp_task[task_no].FLOS;
  299.     if ( FLOS != 0 ) 
  300.         CWK_CUR_LINE(temp_task[task_no].MON, 
  301.            temp_task[task_no].CL - FLOS, "   ");
  302.     if (( FLOS == 0 ) ||